<template>
  <div>
    <div class="search">
      <!-- 顶部 -->
      <div class="search_top">
        <span class="iconfont iconjiantou2" @click="go_back"></span>
        <div class="search_main">
          <span class="iconfont iconsearch"></span>
          <input type="text" placeholder="开始您的搜索" v-model="search_value" />
        </div>
        <button @click="search_click">搜索</button>
      </div>
      <!-- homeBar -->
      <!--       
      <homeBar :v-if="search_value.length >= 1" v-for="item of news_list" 
      :key="item" :newsList="item"></homeBar>-->

      <homeBar
        :v-if="search_value.length >= 1"
        v-for="(item,index) of news_list"
        :key="index"
        :newsList="item"
      ></homeBar>

      <!-- speediness 快速通道 -->
      <div v-if="news_list.length < 1" class="speediness">
        <!-- 历史记录 -->
        <div class="history">
          <h2>历史记录</h2>
          <div class="history_list">
            <span v-for="item of history_list" :key="item">{{item}}</span>
          </div>
        </div>
        <!-- 热门搜索 -->
        <div class="hot">
          <h2>热门搜索</h2>
          <div class="hot_list">
            <span v-for="item of hot_list" :key="item">{{item}}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import homeBar from "../components/homeBar";
export default {
  data() {
    return {
      search_value: "",
      history_list: ["篮球", "球鞋", "音乐", "明星"],
      hot_list: [
        "全球十大首富",
        "最火最新的电视剧",
        "什么是人到中年",
        "办公室勾心斗角",
        "如何中500万彩票"
      ],
      news_list: []
    };
  },
  methods: {
    go_back() {
      if (this.news_list.length > 0) {
        this.news_list = [];
        this.search_value = ''
      } else {
        this.$router.back();
      }
    },
    search_click() {
      this.$axios({
        method: "get",
        url: "/post_search",
        params: {
          keyword: this.search_value
        }
      }).then(res => {
        const { data } = res.data;
        this.news_list = data;
        if (data.length < 1) {
          this.$notify("搜索不到");
        }
      });
    }
  },
  components: {
    homeBar
  }
};
</script>

<style lang="less" scoped>
.search_top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  .search_main {
    border: 1px solid #000;
    width: 66.667vw;
    height: 9.722vw;
    border-radius: 4.861vw;
    display: flex;
    align-items: center;
    .iconsearch {
      padding: 0 2.778vw;
    }
    input {
      outline: none;
      border: 0;
    }
  }
  button {
    outline: none;
    border: 0;
    background: transparent;
    font-size: 4.444vw;
  }
}
.history,
.hot {
  padding: 5.556vw;
  h2 {
    font-size: 5vw;
  }
  .history_list,
  .hot_list {
    padding-top: 2.778vw;
    display: flex;
    flex-wrap: wrap;
    > span {
      padding: 2.222vw;
    }
  }
}
</style>